package com.springboot.dubbo.provider.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ThreadLocalContainer {

    private static ThreadLocal<Map<String, Object>> CACHE = new ThreadLocal<Map<String, Object>>() {
        @Override
        protected Map<String, Object> initialValue() {
            return new ConcurrentHashMap<>();
        }
    };


    public static Object get(String key) {
        return CACHE.get().get(key);
    }


    public static void set(String key, Object val) {
        CACHE.get().put(key, val);
    }


    public static Object remove(String key) {
        return CACHE.get().remove(key);
    }

    public static Map<String, Object> clean() {
        Map<String, Object> map = CACHE.get();
        CACHE.remove();
        return map;
    }

}
